#include <fstream>
#include <iostream>
#include <stdlib.h>
std::string value;
int len = value.length();
void write_file(std::string str_value)
{
    std::ofstream file;
    file.open(("file.bin"), std::ios::out | std::ios::binary);
    file.write((char*)&str_value,len);
    file.close();
}
void read_file(std::string str_value)
{
    std::ifstream file;
    file.open(("file.bin"), std::ios::in | std::ios::binary);
    char * buffer = new char [len];
    file.read(buffer, len);
    std::cout << (buffer);
    file.close();
}
int main()
{
    std::cout <<("Options: \n") << ("W :") << ("Write a string in binary to a file.") << std::endl <<  ("R :")  << ("Read previosly created file.") << std::endl << ("Choose an option: ") << std::endl;
    char x;
    std::cin >> x;
    std::cout << ("Enter a string to be stored as binary in a file and read later: ") << std::endl;
    std::cin >> (value);
    switch(x)
    {
    case 'w' :
        write_file(value);
        break;
    case 'r':
        read_file(value);
        break;
    default:
        std::cerr << ("Invalid option!") << std::endl;
        return 1;
        break;
    }
    return 0;
}
